package com.Maykk.Demo05;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @ClassName: Demo01
 * @Description: TODO TCP 发送练习
 * @Author: MaykkStar@163.com
 */
public class Demo01 {
    public static void main(String[] args) throws IOException {
        // 实例化客户端 Socket 对象
        Socket socket = new Socket(InetAddress.getByName("Star"), 9527);

        // 发送数据
        OutputStream os = socket.getOutputStream();
        os.write("Hello Maykk!~".getBytes());

        // 接收反馈
        InputStream is = socket.getInputStream();
        byte[] data = new byte[1024];
        int length = is.read(data);
        System.out.println("服务器 > " + new String(data, 0, length));

        // 释放资源
        socket.close();

    }
}
